﻿Imports System.Net.Mail

Public Class sendEmail

    Private _smtp As String
    Private _user As String
    Private _pass As String
    Private _message As String
    Private _mailTo As String
    Private _ssl As Boolean


    Sub New(ByVal smtpServer As String, ByVal userName As String, ByVal smtpPass As String, ByVal mailTo As String, ByVal message As String, ByVal useSSL As Boolean)
        _smtp = smtpServer
        _user = userName
        If smtpPass = "" Then
            'MessageBox.Show("Enter smtp Password now")
            _pass = InputBox("Enter password now", "Password Once off")
        Else
            _pass = smtpPass
        End If

        _message = message
        _mailTo = mailTo
        _ssl = useSSL
    End Sub


    Sub sendMail()
        Dim mail As MailMessage = New MailMessage()

        mail.To.Add(_mailTo)
        'mail.To.Add("amit_jain_online@yahoo.com")
        mail.From = New MailAddress(_user)
        mail.Subject = "Automated Email from MagentoBridge"

        mail.Body = _message

        mail.IsBodyHtml = False

        Dim smtp As SmtpClient = New SmtpClient()
        smtp.Host = _smtp

        smtp.Credentials = New System.Net.NetworkCredential(_user, _pass)
        'smtp.Credentials = New System.Net.NetworkCredential("pkula.uk@gmail.com", "123")
        If _ssl Then
            smtp.EnableSsl = True
            smtp.Port = 465
        Else
            smtp.EnableSsl = False
        End If

        Try
            smtp.Send(mail)


        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try



    End Sub

End Class
